package util

import (
	"gitee.com/visons/gopkg/util/math"
	"time"
)

const (
	KSecondsOneDay  = 60 * 60 * 24
	kSecondsOneWeek = KSecondsOneDay * 7
)

func IsSameDay(now, last int64) bool {
	n := time.Unix(now, 0)
	l := time.Unix(last, 0)
	return (n.Day() == l.Day()) && (math.AbsInt64(now-last) < KSecondsOneDay)
}

func IsSameWeek(now, last int64) bool {
	ny, nw := time.Unix(now, 0).ISOWeek()
	ly, lw := time.Unix(last, 0).ISOWeek()
	return (ny == ly) && (nw == lw)
}

func IsSameMoth(now, last int64) bool {
	ny, nm, _ := time.Unix(now, 0).Date()
	ly, lm, _ := time.Unix(last, 0).Date()
	return (ny == ly) && (nm == lm)
}
